package com.huangliusong.order.service.impl;

import com.huangliusong.order.dataobject.OrderMaster;
import com.huangliusong.order.dto.OrderDTO;
import com.huangliusong.order.enums.OrderStatus;
import com.huangliusong.order.enums.PayStatus;
import com.huangliusong.order.repository.OrderDetailRepository;
import com.huangliusong.order.repository.OrderMasterRepository;
import com.huangliusong.order.service.OrderService;
import com.huangliusong.order.utils.KeyUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * @author huangliusong
 * @since 2018/10/20
 * {@link }
 */
@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderDetailRepository orderDetailRepository;
    @Autowired
    private OrderMasterRepository orderMasterRepository;


    @Override
    public OrderDTO create(OrderDTO orderDTO) {
        OrderMaster orderMaster=new OrderMaster();
        orderDTO.setOrderId(KeyUtil.genUnipuKey());
        BeanUtils.copyProperties(orderDTO,orderMaster);
        orderMaster.setOrderAmount(new BigDecimal(21));
        orderMaster.setOrderStatus(OrderStatus.NEW.getCode());
        orderMaster.setPayStatus(PayStatus.NEW.getCode());


        orderMasterRepository.save(orderMaster);
        return orderDTO;
    }
}
